﻿using EPE.BLL;
using EPE.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace EPE.WPF
{
    /// <summary>
    /// UCShopsList.xaml 的交互逻辑
    /// </summary>
    public partial class UCShopsList : UserControl
    {
        public UCShopsList()
        {
            InitializeComponent();
        }

        CLoginUser userinfo = new CLoginUser();
        public UCShopsList(CLoginUser pargUserinfo)
        {
            InitializeComponent();
            userinfo = pargUserinfo;
            BindData();
            
        }

        private void btnSearch_Click(object sender, RoutedEventArgs e)
        {
            BindData();
        }

        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            ShopsAddForm frm = new ShopsAddForm(userinfo);
            frm.ShowDialog();
        }

        private void btnEdit_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var drv = (DataRowView)this.dgList.SelectedItem;
                int iId = Convert.ToInt32(drv["shopsid"]);
                ShopsEditForm edit = new ShopsEditForm(userinfo);
                edit.ShowInfo(iId);
                edit.ShowDialog();
                BindData();
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }

        private void btnDel_Click(object sender, RoutedEventArgs e)
        {

        }

        public void BindData()
        {


            DataSet ds = new DataSet();



            Shops bll = new Shops();


            ds = bll.GetListByPage(this.txtName.Text,this.txtBuildName.Text,this.txtShopsName.Text, userinfo.CompanyId.ToString(), "projectname", this.pagectrl.PageIndex, this.pagectrl.PageSize);

            DataTable dt = ds.Tables[0];

            this.dgList.DataContext = dt;
            this.pagectrl.TotalCount = Convert.ToInt32(ds.Tables[1].Rows[0][0]);
        }

        private void pagectrl_PagerIndexChanged(object sender, EventArgs e)
        {
            BindData();
        }
    }
}
